package cn.lysj.framework.elm.repository;

import cn.lysj.framework.base.BaseRepository;
import cn.lysj.framework.elm.domain.ElmOrder;
import cn.lysj.framework.order.domain.FoodOrder;
import io.swagger.models.auth.In;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * @author drj
 * @description 饿了么订单数据处理层
 * @create 2019-01-21 16:35:47
 **/
public interface ElmOrderRepository extends BaseRepository<ElmOrder> {

    List<ElmOrder> findByStoreIdAndPrint(String storeId, Integer print);

    ElmOrder findByOrderNumber(String orderNumber);


    Page<ElmOrder> findByStoreIdAndOrderStatusIn(String storeId, Integer[] orderStatus, Pageable pageable);


    @Query("select a from ElmOrder a where a.storeId = ?1 and a.orderStatus in ?2 and a.createTime >= ?3 and a.createTime <?4")
    List<ElmOrder> getNewFoodOrders(String storeId, Integer[] orderStatus, Date beginTime, Date endTime);

    List<ElmOrder> findByStoreIdAndPrintAndOrderStatusInOrderByCreateTimeDesc(String storeId, Integer printType, Integer[] foodOrderStatus);

    //模板消息推送
    @Query(value = "SELECT store_id, count(*) FROM elm_order  WHERE  print=1 AND create_time<?1 GROUP BY  store_id",nativeQuery = true)
    List<Object[]> countElmOrderNum(String time);


    //---------销售报表订单统计----------------
    @Query(value = "SELECT DATE_FORMAT(create_time,'%Y-%m-%d') days,COUNT(*)  FROM elm_order WHERE  " +
            " order_status=12 AND store_id=?1 AND (create_time BETWEEN ?2 AND ?3)   GROUP BY days", nativeQuery = true)
    List<Object[]> elmOrderNum(String storeId, Date begin_date, Date end_date);
}